package com.example.alarmcontrolpanel;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MyAlarmDatabase extends SQLiteOpenHelper
{
	
	private static final String CREATE_STATEEMENT=
	"create table if not exist AlarmDataBase" +
	"(alarm_id integer primary key AUTOINCREMENT," +
	" description text," +
	" repeatType integer," +
	" repeatDay text," +
	" millis text)";
	
	
	public MyAlarmDatabase(Context context)
	{
		super(context, "AlarmManagerDB.db", null, 1);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void onCreate(SQLiteDatabase db)
	{
		//db = SQLiteDatabase.openOrCreateDatabase("AlarmManagerDatabase.db", Context.MODE_PRIVATE, null);
		db.execSQL("drop table AlarmDataBase");
		db.execSQL(CREATE_STATEEMENT);
	}
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		Log.w("TaskDBAdapter", "Upgrading from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
		// The simplest case is to drop the old table and create a new one.
		db.execSQL("create table alarm_standby as select * from AlarmDataBase");
		db.execSQL("DROP TABLE IF EXISTS AlarmDataBase");
		db.execSQL("create table AlarmDataBase as select * from alarm_standby");
		db.execSQL("drop table alarm_standby");
	}
}
